
from QCommand import QCommand, CmdIDGen
from Cube.utility.SerialNumberGen import SerialNumberGen
# event
from EventDefine import event_QCMD_MEMBERJOIN

class QCmdMemberJoin(QCommand):
    CMDID = CmdIDGen()
    CMDNAME = "QCmdMemberJoin"
    # setup param encode
    paramIDGen = SerialNumberGen().Gen
    param_memName = paramIDGen()
    param_memType = paramIDGen()
    param_memID = paramIDGen()

    def Send(self, memberName, memberType, memID):
        # encode param
        param = {QCmdMemberJoin.param_memName:memberName,
                 QCmdMemberJoin.param_memType:memberType,
                 QCmdMemberJoin.param_memID:memID
                 }
        QCommand.InputSend(self, memberID = QCommand.MyMemberID, param = param)

    def Handle(self, memberID, param):
        # decode param
        memberName = param[QCmdMemberJoin.param_memName]
        memberType = param[QCmdMemberJoin.param_memType]
        memID = param[QCmdMemberJoin.param_memID]
        # raise event
        messenger.send(event_QCMD_MEMBERJOIN, [memberName, memberType, memID])
